set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/* *******************************************************************
** DATE :
** Writer :
** Memo :
******************************************************************** */
CREATE PROCEDURE [dbo].[TSP_Event_Modify]
(
	@IsTransaction	tinyint			= 0
,	@ErrorCode		int				= 0		OUTPUT
,	@ErrorMessage	nvarchar( 1000 )= ''	OUTPUT

,	@n4EventSN	int	
,	@strEventStart	nvarchar(50)	= null
,	@strEventEnd	nvarchar(50)		= null
,	@strPublicationDate	nvarchar(50)		= null
,	@strImageUrl	varchar(1000)	= null
,	@strBigImageUrl	varchar(1000)	= null
,	@strTitle	nvarchar(400)		= null
,	@strContent	nvarchar(MAX)		= null
,	@isShow	bit						= null
,	@strManagerName	nvarchar(50)	= null


,	@strBigImageUrl2	varchar(1000)	= NULL
,	@strBigImageUrl3	varchar(1000)	= NULL
,	@strBigImageUrl4	varchar(1000)	= NULL
,	@strBigImageUrl5	varchar(1000)	= NULL
,	@strBigImageUrl6	varchar(1000)	= NULL
,	@strBigImageUrl7	varchar(1000)	= NULL
,	@strBigImageUrl8	varchar(1000)	= NULL
,	@strBigImageUrl9	varchar(1000)	= NULL
,	@strBigImageUrl10	varchar(1000)	= NULL
,	@CodeContent		tinyint		= NULL

)
as
Set NOCOUNT ON

-- Frk Default Value
DECLARE @FrkDateNow DateTime
DECLARE @FrkRowCount int
DECLARE @FrkTranCount int
DECLARE @FrkErrorCode int
DECLARE @FrkErrorMessage nvarchar( 1000 )
Set @FrkDateNow = GetDate()
set @FrkTranCount = @@TRANCOUNT
-- Frk Check


If ( @IsTransaction = 0 )
Begin
	If ( @FrkTranCount < 1 )
	Begin
		Set @FrkErrorCode = -1
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Else If ( @FrkTranCount > 1 )
	Begin
		Set @FrkErrorCode = -2
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
End
Else
Begin
	If ( @FrkTranCount <> 0 )
	Begin
		Set @FrkErrorCode = -3
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Begin Tran
End

-- Implementation


UPDATE
	dbo.TB_Event
SET
	strEventStart = IsNull( @strEventStart, strEventStart )
,	strEventEnd = IsNull( @strEventEnd, strEventEnd )
,	strPublicationDate = IsNull( @strPublicationDate, strPublicationDate )
,	strImageUrl = IsNull( @strImageUrl, strImageUrl )
,	strBigImageUrl = IsNull( @strBigImageUrl, strBigImageUrl )
,	strTitle = IsNull( @strTitle, strTitle )
,	strContent = IsNull( @strContent, strContent )
,	isShow = IsNull( @isShow, isShow )
,	strManagerName = IsNull( @strManagerName, strManagerName )
,	strBigImageUrl2 = IsNull( @strBigImageUrl2, strBigImageUrl2 )
,	strBigImageUrl3 = IsNull( @strBigImageUrl3, strBigImageUrl3 )
,	strBigImageUrl4 = IsNull( @strBigImageUrl4, strBigImageUrl4 )
,	strBigImageUrl5 = IsNull( @strBigImageUrl5, strBigImageUrl5 )
,	strBigImageUrl6 = IsNull( @strBigImageUrl6, strBigImageUrl6 )
,	strBigImageUrl7 = IsNull( @strBigImageUrl7, strBigImageUrl7 )
,	strBigImageUrl8 = IsNull( @strBigImageUrl8, strBigImageUrl8 )
,	strBigImageUrl9 = IsNull( @strBigImageUrl9, strBigImageUrl9 )
,	strBigImageUrl10 = IsNull( @strBigImageUrl10, strBigImageUrl10 )
,	CodeContent = IsNull( @CodeContent, CodeContent )
WHERE
	n4EventSN = @n4EventSN


-- Frk Error Check
SELECT
	@FrkErrorCode = @@ERROR
,	@FrkRowCount = @@RowCount

-- End

COMPLETE:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Commit Tran
		End
	End
	SET @ErrorCode = 0
	SET @ErrorMessage = ''
	return 0
ERROR:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Rollback Tran
		End
	End
	SET @ErrorCode = @FrkErrorCode
	SET @ErrorMessage = @FrkErrorMessage
	return @FrkErrorCode
